﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pages_qcsicomill_leco_carbon : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        handleEditMode();
    }

    //protected void btnSave_Click(object sender, EventArgs e)
    //{
    //    if (btnSave.CommandArgument == "")
    //    {
    //        tbl_qcsicomill_leco_carbon model = new tbl_qcsicomill_leco_carbon();
    //        model.PO_NUMBER = txtPO_NUMBER.Text.Trim();
    //        model.DRUM_NUMBER = txtDRUM_NUMBER.Text.Trim();
    //        model.C_VALUE = txtC_VALUE.Text.Trim();
    //        model.REMARK = txtREMARK.Text.Trim();
    //        model.IS_ACTIVE = true;
    //        model.CREATED_BY = User.Identity.Name;
    //        model.CREATED_DATE = DateTime.Now;



    //        BLL_tbl_qcsicomill_leco_carbon bll = new BLL_tbl_qcsicomill_leco_carbon();
    //        bll.insert(model);
    //    }
    //    else
    //    {
    //        tbl_qcsicomill_leco_carbon model = new tbl_qcsicomill_leco_carbon();
    //        model.QC_Leco_Carbon_ID = btnSave.CommandArgument.Trim();
    //        model.PO_NUMBER = txtPO_NUMBER.Text.Trim();
    //        model.DRUM_NUMBER = txtDRUM_NUMBER.Text.Trim();
    //        model.C_VALUE = txtC_VALUE.Text.Trim();
    //        model.REMARK = txtREMARK.Text.Trim();
    //        model.IS_ACTIVE = true;
    //        model.UPDATED_BY = User.Identity.Name;
    //        model.UPDATED_DATE = DateTime.Now;



    //        BLL_tbl_qcsicomill_leco_carbon bll = new BLL_tbl_qcsicomill_leco_carbon();
    //        bll.update(model);
    //        btnSave.CommandArgument = "";
    //        Response.Redirect(Request.Url.AbsolutePath);
    //    }
    //}

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.Url.AbsolutePath);
    }

    protected void linkDelete_Click(object sender, EventArgs e)
    {
        string id = ((LinkButton)sender).CommandArgument;
        tbl_qcsicomill_leco_carbon model = new tbl_qcsicomill_leco_carbon();
        model.QC_Leco_Carbon_ID = id.ToString();

        BLL_tbl_qcsicomill_leco_carbon bll = new BLL_tbl_qcsicomill_leco_carbon();
        bll.delete(model);
    }

    protected void linkEdit_Click(object sender, EventArgs e)
    {
        string id = ((LinkButton)sender).CommandArgument;
        Response.Redirect(Request.Url.AbsolutePath + "?editRecord=" + id);
    }


    protected void handleEditMode()
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["editRecord"] != null)
            {
                string id = Request.QueryString["editRecord"];
                BLL_tbl_qcsicomill_leco_carbon bll = new BLL_tbl_qcsicomill_leco_carbon();
                List<tbl_qcsicomill_leco_carbon> list = bll.select(id);
                foreach (tbl_qcsicomill_leco_carbon tbl in list)
                {
                    //btnSave.CommandArgument = tbl.QC_Leco_Carbon_ID.ToString();
                    ddlWork_Order_Number.Attributes.Add("SelectedVal", tbl.Work_Order_Number);
                    ddlDRUM_Number.Attributes.Add("SelectedVal", tbl.DRUM_NUMBER);
                    //txtBudgeted_Qty.Text = tbl.Budgeted_Qty.ToString();
                    //txtActual_Qty.Text = tbl.Actual_Qty.ToString();
                    txtC_VALUE.Text = tbl.C_VALUE;
                    txtREMARK.Text = tbl.REMARK;
                }
                string script = "$('#MainContent_Add_ddlWork_Order_Number').val($('#MainContent_Add_ddlWork_Order_Number').attr('selectedval'));";
                script += "getDrums();";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "BindDrum", script, true);
            }
        }
    }



    protected void ddlWork_Order_Number_DataBound(object sender, EventArgs e)
    {
        ListItem li = new ListItem("--Select--", "0");
        ddlWork_Order_Number.Items.Insert(0, li);
    }
    
}